package main

import (
	"fmt"
	"geneticA/ga"
	"time"
)

func main() {
	mainPro := ga.NewMainProcess()
	mainPro.SetFuncHandler(fitness)
	now := time.Now().UnixNano()
	mainPro.Run(200, 3, 100000, 50, -3.048, 3.048, 99.99, 7.015, 0.005)
	now2 := time.Now().UnixNano()
	fmt.Println("spent time:", (now2-now)/1e6, "ms")
}

func fitness(c *ga.Chromosome) float64 {
	if len(c.DataArray) < 2 {
		fmt.Println("data array err")
		return 0
	}
	v1 := c.DataArray[0]
	v2 := c.DataArray[1]

	y := (v1-2.383)*(v1-2.383)/2 + (v2-128.383)*(v2-128.383)/3
	return 1.0 / (y + 0.01)
}
